package org.tio.sitexxx.im.client.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.core.ChannelContext;
import org.tio.core.Tio;
import org.tio.sitexxx.im.common.Command;
import org.tio.sitexxx.im.common.CommandHandler;
import org.tio.sitexxx.im.common.ImPacket;
import org.tio.sitexxx.im.common.ImSessionContext;
import org.tio.sitexxx.im.common.bs.JoinGroupReq;
import org.tio.sitexxx.im.common.utils.ImUtils;
import org.tio.sitexxx.service.vo.Const;

/**
 *
 * @author tanyaowu
 * 2016年5月9日 上午11:46:24
 */
@CommandHandler(Command.HANDSHAKE_RESP)
public class HandshakeRespHandler implements ImClientHandler {
	@SuppressWarnings("unused")
	private static Logger log = LoggerFactory.getLogger(HandshakeRespHandler.class);

	public HandshakeRespHandler() {

	}

	@Override
	public void handler(ImPacket packet, ChannelContext channelContext) throws Exception {
		ImSessionContext imSessionContext = ImUtils.getImSessionContext(channelContext);
		imSessionContext.setHandshaked(true);

		JoinGroupReq joinGroupReq = new JoinGroupReq();
		joinGroupReq.setG(Const.TEST_GROUPID);

		ImPacket respPacket = new ImPacket(Command.JOIN_GROUP_REQ, joinGroupReq);
		Tio.send(channelContext, respPacket);
		return;
	}

}
